package edu.sctu.practice.class02.hujie.cgs.assign08.three;

import java.io.*;
import java.net.*;
import java.util.zip.DeflaterInputStream;

/**
 * Created by hp on 2015/12/21.
 */
public class ServerThread extends Thread {
    InetAddress address;
    DataOutputStream out = null;//输出流
    DeflaterInputStream in = null;
    String s = null;

    ServerThread(InetAddress address) {
        this.address = address;
    }

    public void run() {
        FileInputStream in;
        byte b[] = new byte[8192];
        try {
            in = new FileInputStream("a.jpg");
            int n = -1;
            while ((n = in.read(b)) != -1) {
                DatagramPacket data = new DatagramPacket(b, n, address, 5678);
                DatagramSocket mailSend = new DatagramSocket();
                mailSend.send(data);
            }
            in.close();
            byte end[] = "end".getBytes();
            DatagramPacket data = new DatagramPacket(end, end.length, address, 5678);
            DatagramSocket mailSend = new DatagramSocket();
            mailSend.send(data);
        } catch (Exception e) {}
    }
}
